import { result, mockPageRes, qsparse } from '../util'
import Mock from 'mockjs'
const mockOrderList = (params) => result(() => {
  const status = [0, 1]
  const statusText = ['未提交', '已提交']
  const data = Mock.mock({
    'orderList|10': [{
      'orderNo': /N[0-9]{7}/,
      'customerCode': /C[0-9]{4}/,
      'customerName': '@city()@ctitle(3)有限公司',
      'status|+1': status,
      'statusText|+1': statusText,
      'remark': '@cparagraph',
      'orderAmount|100-100.2-2': 100,
      'orderActualAmount|100-100.2-2': 120,
      'chargePerson': '@cname',
      'orderCreateTime': '@datetime',
      'completionTime': '@datetime',
      'deliveryTime': '@datetime',
      'createTime': '@now',
      'updateTime': '@now',
      'creater': '@cname'
    }]
  })
  return mockPageRes(params, data.orderList)
})

const mockReceiveInfo = (params) => result(() => {
  // const orderNo = params.orderNo
  const contacInfo1 = { orderNo: 'N00001', contactsName: '刘花丽', contactsCode: '', mobilephone: '13012887711', address: '北京市昭阳区', remark: '货到付款' }
  const contacInfo2 = { orderNo: 'N00002', contactsName: '王大锤', contactsCode: '', mobilephone: '13012887712', address: '北京市昭阳区', remark: '货到付款' }
  const contacInfo3 = { orderNo: 'N00003', contactsName: '欧阳娜娜', contactsCode: '', mobilephone: '13012887713', address: '北京市昭阳区', remark: '货到付款' }
  const contacts = [contacInfo1, contacInfo2, contacInfo3]
  return contacts ? contacts[0] : {}
})

const mockPorductList = () => result(() => {
  const p1 = { productCode: 'P0001', productName: '滚珠丝杆', tag: 1, model: 'M0012', productNum: 10, price: 12.11, actualPrice: 10.11, discountRate: 0.8, tatolAmount: 10.11 * 10, discountTatolAmount: 10.11 * 10 * 0.8 }
  const p2 = { productCode: 'P0002', productName: 'LGD导轨', tag: 3, model: 'M0014', productNum: 2, price: 33.23, actualPrice: 32.22, discountRate: 0.7, tatolAmount: 32.22 * 2, discountTatolAmount: 32.22 * 2 * 0.7 }
  const p3 = { productCode: 'P0003', productName: 'LGD导轨2', tag: 3, model: 'M0015', productNum: 4, price: 89.90, actualPrice: 80.00, discountRate: 0.7, tatolAmount: 80.00 * 4, discountTatolAmount: 80.00 * 4 * 0.7 }
  const productInfoList = [p1, p2, p3]
  return productInfoList
})
export default {
  'post|/api/getOrderInfoList': (option) => {
    const params = qsparse(option.body)
    return mockOrderList(params)
  },
  'post|/api/getReceiveInfo': (option) => {
    const params = qsparse(option.body)
    return mockReceiveInfo(params)
  },
  'post|order/getOrderPorductList': mockPorductList
}
